import tkinter as tk
from tkinter import messagebox
from db import db
from AdminViews import InsertFrame, SelectFrame, DeleteFrame, ChangeFrame, AttendFrame, LeaveFrame


class AdminPage:
    def __init__(self, root):
        self.root = root
        self.root.title('员工管理系统')
        self.root.geometry('600x400')
        #创建菜单栏
        self.create_page()
        # 初始化菜单按钮数据
        self.init_show()



    def create_page(self):
        menubar = tk.Menu(self.root)
        menubar.add_command(label='录入员工信息', command=self.show_insert)
        menubar.add_command(label='查询员工信息', command=self.show_select)
        menubar.add_command(label='删除员工信息', command=self.show_delete)
        menubar.add_command(label='修改员工信息', command=self.show_change)
        menubar.add_command(label='查看员工考勤记录', command=self.show_attend)
        menubar.add_command(label='查看员工请假申请', command=self.show_leave)
        self.root['menu'] = menubar

    #初始化菜单类
    def init_show(self):
        self.insert_frame = InsertFrame(self.root)
        self.select_frame = SelectFrame(self.root)
        self.delete_frame = DeleteFrame(self.root)
        self.change_frame = ChangeFrame(self.root)
        self.attend_frame = AttendFrame(self.root)
        self.leave_frame = LeaveFrame(self.root)





    #显示插入功能
    def show_insert(self):
        self.insert_frame.entry_clear()
        self.insert_frame.pack()
        # 隐藏无关界面
        self.select_frame.pack_forget()
        self.delete_frame.pack_forget()
        self.change_frame.pack_forget()
        self.attend_frame.pack_forget()
        self.leave_frame.pack_forget()


    #显示查询功能
    def show_select(self):
        self.select_frame.show_clear()
        self.select_frame.pack()
        # 隐藏无关界面
        self.insert_frame.pack_forget()
        self.delete_frame.pack_forget()
        self.change_frame.pack_forget()
        self.attend_frame.pack_forget()
        self.leave_frame.pack_forget()

    # 显示删除功能
    def show_delete(self):
        self.delete_frame.e1.delete(0, "end")
        self.delete_frame.pack()
        # 隐藏无关界面
        self.insert_frame.pack_forget()
        self.select_frame.pack_forget()
        self.change_frame.pack_forget()
        self.attend_frame.pack_forget()
        self.leave_frame.pack_forget()



    # 显示修改功能
    def show_change(self):
        self.change_frame.entry_clear()
        self.change_frame.pack()
        # 隐藏无关界面
        self.insert_frame.pack_forget()
        self.select_frame.pack_forget()
        self.delete_frame.pack_forget()
        self.attend_frame.pack_forget()
        self.leave_frame.pack_forget()

    #显示员工考勤功能
    def show_attend(self):
        self.attend_frame.pack()
        # 隐藏无关界面
        self.insert_frame.pack_forget()
        self.select_frame.pack_forget()
        self.delete_frame.pack_forget()
        self.change_frame.pack_forget()
        self.leave_frame.pack_forget()



    def show_leave(self):
        self.leave_frame.show_clear()
        self.leave_frame.entry_clear()
        self.leave_frame.pack()
        # 隐藏无关界面
        self.insert_frame.pack_forget()
        self.select_frame.pack_forget()
        self.delete_frame.pack_forget()
        self.change_frame.pack_forget()
        self.attend_frame.pack_forget()


if __name__ == '__main__':
    root = tk.Tk()
    app = AdminPage(root)
    root.mainloop()
